home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / formset / unit1.pas < prev   
Pascal/Delphi Source File  |  1996-04-08  |  3KB  |  106 lines

  1. {
  2.                                Saxman Software
  3.                         Programmer Productivity Series
  4.                              Delphi Custom Controls
  5.                          Copyright 1995, Jim Standley
  6.  
  7.                            FormSet Demo, Main Form
  8. }
  9. {
  10.    Example code using the FormSet control. This is the "parent" or "book"
  11.    form. It has the FormSet control on it. The FormSet displays "child" or
  12.    "page" forms in the client area of the parent.
  13.  
  14.    This unit has the OnTabLoad event handler.  This procedure maps TForm
  15.    objects onto the tabs.  It is called any time a tab is selected and
  16.    FormSet does not already have the TForm object for that tab.
  17.  
  18.    Another important point is to set FormSet1.TabIndex to a valid tab index
  19.    before the main form is seen by the user.  This triggers a Change event
  20.    within FormSet which is needed to display the first tab and form.
  21. }
  22. Unit Unit1;
  23.  
  24. interface
  25.  
  26. uses
  27.   SysUtils, Classes, Forms, Dialogs,  Tabs, Controls, Formset, ExtCtrls;
  28.  
  29. type
  30.   TForm1 = class(TForm)
  31.     FormSet1: TFormSet;
  32.     procedure FormCreate(Sender: TObject);
  33.     procedure FormSet1Change(Sender: TObject; NewTab: Integer;
  34.       var AllowChange: Boolean);
  35.     procedure FormSet1Click(Sender: TObject);
  36.     procedure FormSet1TabLoad(Sender: TObject; TabIndex: Integer;
  37.       FormTab: TFormTab);
  38.   private
  39.     { Private declarations }
  40.   public
  41.     { Public declarations  }
  42.   end;
  43.  
  44. var
  45.   Form1: TForm1;
  46.  
  47. implementation
  48. {$R *.DFM}
  49. uses Page1, Page2, Page3;
  50.  
  51. {------------------------------  Form Create  -------------------------------}
  52. procedure TForm1.FormCreate(Sender: TObject);
  53. begin
  54.    FormSet1.TabIndex := 0;  { Necessary to trigger first Change }
  55. end;
  56.  
  57. {----------------------------  FormSet Change  ------------------------------}
  58. procedure TForm1.FormSet1Change(Sender: TObject; NewTab: Integer;
  59.    var AllowChange: Boolean);
  60. begin
  61.    ShowMessage(format('FormSet: Change (TabIndex=%d, NewTab=%d)',
  62.       [FormSet1.Tabindex,NewTab]));
  63. end;
  64.  
  65. {-----------------------------  FormSet Click  ------------------------------}
  66. { Fired after all the interesting bits have happened and the new page is     }
  67. { visible.                                                                   }
  68. procedure TForm1.FormSet1Click(Sender: TObject);
  69. begin
  70.    ShowMessage('FormSet: Click.');
  71. end;
  72.  
  73. {----------------------------  FormSet TabLoad  -----------------------------}
  74. { Fired by FormSet when the form for a page is not known.  This routine must }
  75. { load FormTab.Form.  It can optionally override defaults for other FormTab  }
  76. { properties.                                                                }
  77. procedure TForm1.FormSet1TabLoad(Sender: TObject; TabIndex: Integer;
  78.   FormTab: TFormTab);
  79. var
  80.    Caption : String;
  81. begin
  82.    Caption := FormSet1.Tabs[TabIndex];
  83.    if Caption = 'Page &1' then
  84.    begin
  85.       FormTab.Form    := TfPage1.Create(Self);
  86.       FormTab.OnOpen  := ftoSizeBookToPage;
  87.       FormTab.OnClose := ftcAlwaysRelease;
  88.    end
  89.    else
  90.    if Caption = 'Page &2' then
  91.    begin
  92.       FormTab.Form    := TfPage2.Create(Self);
  93.       FormTab.OnOpen  := ftoSizePageToBook;
  94.       FormTab.OnClose := ftcNeverRelease;
  95.    end
  96.    else
  97.    if Caption = 'Page &3' then
  98.    begin
  99.       FormTab.Form    := fPage3;   { already exists! }
  100.       FormTab.OnOpen  := ftoSizePageToBook;
  101.       FormTab.OnClose := ftcNeverRelease;
  102.    end;;
  103. end;
  104.  
  105. end.
  106.